<body>
    <h2>手术记录</h2>
    <div style="margin:10px 0;"></div>
    <table id="list"></table>


    <div id="RecordDetail" title="手术记录" class="easyui-dialog" closed="true" style="width:850px;height:550px">
    </div>
    
    <div id="tb" style="padding:5px;height:auto">
        <div style="margin-bottom:5px;vertical-align:middle">
            <a href="#" onclick="javascript:workbenchJs.open1('component/customer/addSurgeryRecord.html',this)" class="easyui-linkbutton" iconCls="icon-add" plain="true">增加</a>
            <a href="#" class="easyui-linkbutton"  plain="true">过滤条件：</a>
    		
    		<a href="#"  class="easyui-menubutton" data-options="menu:'#mm1'">客户信息</a>
    		<div id="mm1" class="menu-content" style="background:#f0f0f0;padding:10px;text-align:left;display:none">
    			<form id="findCustomerfm" method="post" novalidate>
            		<div class="fitem">
                		<p>可以通过姓名,手机,QQ,Email,微信等信息查询</p>
            		</div> 
           			<div class="fitem">
                		<input id="customerInfo" name="valueSearch">
            		</div>     
         			<div>
        				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="javascript:surgeryRecordJs.searchByCustomer()">搜索</a>
    				</div>                                              
        		</form>    
    		</div>
        </div>

        <div id="searchFilter">
        </div>
    </div>
    <div id="OpportunityDetail"  class="easyui-dialog"  closed="true" style="width:900px;height:550px">
    </div>
    <script type="text/javascript">
(function(surgeryRecordJs, $, undefined ) {      
	var countPerPage = 5;
	var start = 0;
	var customer_search = '';
	
	surgeryRecordJs.opendiag = function(url,a){
		$('#RecordDetail').dialog("open");
		$('#RecordDetail').dialog('refresh',url);
		
	}
	surgeryRecordJs.clearSearch = function()
	{
		countPerPage = 5;
		start = 0;
		customer_search = '';
		refreshSearchFilter();
		refresh();
	}
	
	$('#list').datagrid({
		title:'手术记录',
		iconCls:'icon-opportunity',
		height:350,
		fitColumns:true,
		singleSelect:true,
		url:null,
		rownumbers:true,
	    columns:[[
					{title:'名称',field:'title',width:80},
	             	{title:'客户信息',field:'customerName',width:80,sortable:true},
	             	{title:'合同编号',field:'contractSequence',width:80,sortable:true},
	             	{title:'主刀医生',field:'doctor',width:80,sortable:true},
	             	{title:'项目',field:'items',width:80,sortable:true},
	             	{title:'手术时间',field:'surgeryTime',width:80,sortable:true},
	             ]],
		pagination:true,
        pageSize:countPerPage,
        pageList:[5,10,15,20,25],
		toolbar:'#tb',
	    onDblClickCell: openSurgeryRecord
	});

	$('#list').datagrid('getPager').pagination({   
	    displayMsg:'当前显示从 [{from}] 到 [{to}] 共[{total}]条记录',   
	    onSelectPage : function(pPageIndex, pPageSize) {   
	    	
	        var gridOpts = $('#list').datagrid('options');   
	        gridOpts.pageNumber = pPageIndex;   
	        gridOpts.pageSize = pPageSize;     

	        start = (pPageIndex -1)*pPageSize;
	        
	        postSearch();
	    },
	    onChangePageSize : function(pageSize){
	    	countPerPage = pageSize;
	    }
	}); 

	surgeryRecordJs.init = function(){
		refresh();
	}
	
	surgeryRecordJs.loadCAData = function(result){
		var res = result.result;
        if(res == "SUCCESS")
        {
    		var payload = jQuery.parseJSON(result.payload.value);
        	$('#list').datagrid('loadData',payload);
        }else if(result.result == "NOT_AUTHORIZED")
        {
        	$.messager.alert("Error","操作: 查询手术记录 错误信息: 您没有权限 ");
        }else if(result.result == "COMPONENT_ERROR")
        {
        	$.messager.alert("Error","操作: 查询手术记录 错误信息: "+result.payload.value);
        }else
        {
        	$.messager.alert("Error","操作: 查询手术记录 错误信息: "+result.result);
        }
        $('#list').datagrid("loaded");
	};


	function simpleResultHanding(result){
    	var res = result.result;
        if(res == "SUCCESS")
        {
        	$.messager.show({
                title: 'success',
                msg: "success"
            });
        }else if(res == "COMPONENT_ERROR")
        {
        	$.messager.alert("Error",result.payload.value);
        }else
        {
        	$.messager.alert("Error",result.result);
        }
	}
	function openSurgeryRecord(){
        var row = $('#list').datagrid('getSelected');
        if (row){
    		$('#RecordDetail').dialog("open").dialog('setTitle','商业机会');
    		$('#RecordDetail').dialog('refresh','component/customer/viewSurgeryRecord.jsp?id='+row.id);
        }else
        	{
        		$.messager.alert("Error","请选择一条记录");
        	}
	}

    function refresh(){
    	$('#list').datagrid("loading");
    	postSearch();
    	
    }


    surgeryRecordJs.searchByCustomer = function(){
		$('#list').datagrid("loading");
		customer_search = $('#customerInfo').val();
		refreshSearchFilter();
		start = 0;
		postSearch();
	}
	function getSearchFilter()
	{
		var html = "查询条件:";
		if(customer_search != "" && typeof(customer_search) != 'undefined')
			html += customer_search;
		
		return html;
	}
	function refreshSearchFilter()
	{

		var html = getSearchFilter();
		html += ' <a href="javascript:void(0)" onclick="javascript:surgeryRecordJs.clearSearch()">清除</a>';
		$('#searchFilter').html(html);
		
	}
	function postSearch()
	{
		var str = "";
		
		str = appendURL(str,"customer="+customer_search);
		str = appendURL(str,'start='+start+'&size='+countPerPage);
		$.ajax({
            type: "post",
            url: "dispatch/customer/surgeryRecord/all",
            dataType:"json",
            data: str,
            cache: false,
            success: function (result) {
            	
            	surgeryRecordJs.loadCAData(result);
            }
		});
	}
	function appendURL(url,str1)
	{
		if(typeof(str1) == 'undefined')return url;
		if(url == "" || typeof(url) == 'undefined')url = str1;
		else url+="&"+str1;

		return url;
	}
}( window.surgeryRecordJs = window.surgeryRecordJs || {}, jQuery ));

    $(function(){
    	surgeryRecordJs.init();
    });  
    </script>
    <style type="text/css">
        #fm{
            margin:0;
            padding:10px 30px;
        }
        .ftitle{
            font-size:14px;
            font-weight:bold;
            padding:5px 0;
            margin-bottom:10px;
            border-bottom:1px solid #ccc;
        }
        .fitem{
            margin-bottom:5px;
        }
        .fitem label{
            display:inline-block;
            width:80px;
        }
        .toolbar_pic {
 			width: 70px;
  			height: 30px;
  			overflow: hidden;
  			display: inline-block;
  			vertical-align: top;
  			cursor: pointer;
  			opacity: 0.6;
  			filter: alpha(opacity=60);
		}
		.toolbar_text {
 			width: 70px;
 			height:100%;
  			overflow: hidden;
  			display: inline-block;
  			vertical-align: middle;
		}
    </style>